package chen.web.test;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import chen.web.MyContext;
import chen.web.MyContextProvider;
import chen.web.user.Account;
import chen.web.user.InternalAccountProvider;

public class SetCurrentAccount {

	static void set(Account account) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, NoSuchFieldException, InstantiationException{
		Method method = MyContextProvider.class.getDeclaredMethod("setMyContext", MyContext.class);
		Constructor cons = MyContext.class.getDeclaredConstructor(null);
		cons.setAccessible(true);
		MyContext context = (MyContext) cons.newInstance(null);
		Field field = context.getClass().getDeclaredField("account");
		Field ipFi = context.getClass().getDeclaredField("ip");
		Field uuidFi = context.getClass().getDeclaredField("uuid");
		uuidFi.setAccessible(true);
		uuidFi.set(context, "57ebea90-1338-11e0-ac64-0800200c9a66");
		ipFi.setAccessible(true);
		ipFi.set(context, "192.163.12.12");
		field.setAccessible(true);
		field.set(context, account);
		method.setAccessible(true);
		method.invoke(cons, context);
	}
}
